home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Sokoban / source / level.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-09  |  4.2 KB  |  153 lines

  1. //---------------------------------------------------------------------------
  2. #ifndef levelH
  3. #define levelH
  4. #include "lang.h"
  5. #pragma warning(disable:4701)
  6. //---------------------------------------------------------------------------
  7. enum{ BM_GROUND,BM_OBJECT,BM_BACKGROUND,BM_STORE,BM_OBJECTSTORE,
  8.  BM_HILITE,BM_HILITESTORE,BM_WALL, BM_MOVER=BM_WALL+5,
  9.  BM_MOVERSTORE=BM_MOVER+4, BM_NUM=BM_MOVERSTORE+4 };
  10. enum{ F_GROUND,F_OBJECT,F_HILITE,F_STORE,F_BACKGROUND,
  11.  F_MOVER,F_WALL,F_NUM };
  12.  
  13. typedef char *Pchar;
  14. typedef unsigned char uchar;
  15. typedef uchar *Puchar;
  16. typedef char TfileName[MAX_PATH];
  17.  
  18. struct Square1 {
  19.  char obj;
  20.  bool store;
  21. };
  22. typedef Square1 *Psquare1;
  23.  
  24. struct Square : public Square1 {
  25.  int x,y,i;
  26.  int dist,finalDist;
  27.  int distId;
  28.  int direct;
  29.  short cont[4];      //think:oznaΦenφ chodby, movePush:ohodnocenφ
  30.  char pushDirect[4]; //movePush:sm∞r hrßΦe od objektu p°ed tφmto p°esunem
  31.  int *finalDists;
  32.  Square(){ store=false; obj=BM_GROUND; }
  33. };
  34. typedef Square *Psquare;
  35.  
  36. inline int eval(int mov,int pus){ return mov ? mov+pus:32767;}
  37.  
  38. struct Solution {
  39.  int Mmoves,Mpushes;
  40.  Pchar Mdata;
  41.  void init(){ Mmoves=Mpushes=0; Mdata=0; }
  42.  Solution(){ init(); }
  43.  int eval(){ return ::eval(Mmoves,Mpushes); }
  44. };
  45.  
  46. struct Level {
  47.  Pchar offset, author;
  48.  Solution best,user;
  49.  int width,height;
  50.  int i;
  51. };
  52.  
  53. struct QuickInfo {
  54.  int mover, pushBeg, pushEnd;
  55.  short mov,pus;
  56. };
  57.  
  58. struct UndoInfo {
  59.  Psquare mover, pushBeg, pushEnd;
  60.  short mov,pus;
  61. };
  62.  
  63. struct EdUndo {
  64.  int x,y;
  65.  char obj;
  66.  bool store;
  67. };
  68. //---------------------------------------------------------------------------
  69. void initUser();
  70. void delUser();
  71. void saveUser();
  72. void saveData();
  73. void saveLevel();
  74. int initLevels();
  75. int loadLevel(int which);
  76. void clearBoard();
  77. void resetLevel();
  78. bool finish();
  79. bool openLevel();
  80. void fillOuter();
  81. void findDist(Psquare src, Psquare dest);
  82. void movLevels(Level *first, Level *last, Level *dest);
  83. int optimizeLevel();
  84. bool wrLevel();
  85. void openPos();
  86. void savePos();
  87. void openUser();
  88. void newBoard(int w,int h,int copy);
  89. void getDim(Pchar buf, int &widht, int &height);
  90. int getNobj(Pchar buf);
  91. Level *addLevel();
  92. void loadSolution(int lev, Pchar p);
  93. bool delLevel(int lev, HWND win);
  94. void wrLog(char ch);
  95. int findSolution(int alg);
  96. void gener();
  97.  
  98. Psquare square(int x,int y);
  99. void msg(char *text, ...);
  100. int msg1(int btn, char *text, ...);
  101. void msg2(char *caption, char *text, ...);
  102. int msg3(int btn, char *caption, char *text, ...);
  103. void setTitle(char *txt);
  104. void getClient(RECT *rc);
  105. void paintSquare(Psquare p);
  106. void repaint();
  107. void update();
  108. void resize();
  109. void status();
  110. void undoAll();
  111. void redoAll();
  112. bool moveK(int direct);
  113. int openFileDlg(OPENFILENAME *o);
  114. int saveFileDlg(OPENFILENAME *o, bool prompt);
  115. //---------------------------------------------------------------------------
  116. extern int Nlevels,playtime,level,quickSaveLevel,width,height,bmW,bmH,
  117.  check,notOptimize,moverDirect,replay,moves,pushes,notMsg,notResize,
  118.  notdraw,movError,gratulOn,diroff[9],distId,MNg;
  119. extern bool modifData,modifUser,editing,rdonly,stopTime;
  120. extern Psquare board,boardk,mover,selected,hilited,*distBuf1,*distBuf2;
  121. extern Pchar user,userk,levels,levelsk,logPos;
  122. extern Level *levoff;
  123. extern QuickInfo *quickSave;
  124. extern UndoInfo rec[8192], *undoPos,*redoPos;
  125. extern EdUndo edRec[1024], *edUndo,*edRedo;
  126. extern char logbuf[32768],*title;
  127.  
  128. extern TfileName fnuser,fndata,fnlevel,fnsave;
  129. extern OPENFILENAME userOfn,levelOfn,dataOfn,savOfn;
  130. extern HWND hWin;
  131. //---------------------------------------------------------------------------
  132. #define sizeA(a) (sizeof(a)/sizeof(*a))
  133. #define endA(a) (a+(sizeof(a)/sizeof(*a)))
  134. #define nxtP(p,s) ((Psquare)(((char*)p)+diroff[s]))
  135. #define prvP(p,s) ((Psquare)(((char*)p)-diroff[s]))
  136. #define isSep(c) ((c)==0 || (c)==';' || (c)=='\r' || (c)=='\n')
  137. #define MAXDIST 15000
  138.  
  139. template <class T> inline void amin(T &x,int m)
  140. {
  141.  if(x<m) x=m;
  142. }
  143. template <class T> inline void amax(T &x,int m)
  144. {
  145.  if(x>m) x=m;
  146. }
  147. template <class T> inline void aminmax(T &x,int l,int h){
  148.  if(x<l) x=l;
  149.  if(x>h) x=h;
  150. }
  151. //---------------------------------------------------------------------------
  152. #endif
  153.